#ifndef _RENDER_DX9_H_
#define _RENDER_DX9_H_

#include "render.h"

#ifdef _DEBUG
#define D3DCHECK(x) {if(FAILED(x)){if(dbg_assert_msg(#x,"DirectX 9 assert")!=IDCANCEL)_asm{int 3};}}
#else
#define D3DCHECK(x) x
#endif

class render_dx9: public render
{
public:
	render_dx9();
	~render_dx9();

	void init(xml_node& _node);
	void reset();
	void free();
	device_state get_state();

	void begin();
	void end();
	void clear(u32 _type,color _color,float _z,u32 _stencil);

	vbuffer* create_vbuffer(buffer_usage _usage,u32 _vformat,u32 _blocksize,u32 _lenth);
	ibuffer* create_ibuffer(buffer_usage _usage,u32 _size);
	void	 set_vbuffer(vbuffer* _vbuffer);
	void	 set_ibuffer(ibuffer* _ibuffer);
	void	 draw_vbuffer(primitiv_type _prtype,u32 _start_vrt,u32 _pr_count);
	void	 draw_ibuffer(primitiv_type _prtype,u32 _num_vtx,u32 _start_idx,u32 _pr_count);
	texture* create_texture(u32 _w, u32 _h,tex_format _fmt);
	void	 set_texture(u32 _stage,texture* _texture);
	effect*  create_effect(file* _file,const char* _vfunc,const char* _pfunc);
	effect*  create_effect(const char* _fname,const char* _vfunc,const char* _pfunc);
	void	 set_effect(effect* _effect);

	void enable_light(bool _enabled);
	void set_light(u32 _stage,light _light);
	void set_material(material _material);
	void set_ambient(color _color);
	void set_cullmode(cull_mode _mode);
	void set_fillmode(fill_mode _mode);

	void set_projection(matrix4 _matrix);
	void set_view(matrix4 _matrix);
	void set_world(matrix4 _matrix);
	void set_viewport(u32 _x,u32 _y,u32 _width,u32 _height);

	IDirect3DDevice9* get_device();

private:

	IDirect3D9				*m_d3d;
	IDirect3DDevice9		*m_d3ddevice;
	D3DPRESENT_PARAMETERS    m_d3dpp;
};

#endif